package com.itheima.d3.EmployeeStream;

import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class Test {
    private  static double sum = 0;
    public static void main(String[] args) {
        DevelopDept emp1 = new DevDept1("A",'男',12343.6,4000,"迟到5次");
        DevelopDept emp2 = new DevDept1("B",'男',12342.6,5000,"迟到5次");
        DevelopDept emp3 = new DevDept1("C",'男',12345.6,6000,"迟到6次");
        DevelopDept emp4 = new DevDept1("D",'男',12346.6,7000,"迟到7次");
        DevelopDept worker1 = new DevDept2("E",'男',12645.6,3000,"迟到4次");
        DevelopDept worker2 = new DevDept2("F",'男',12545.6,1000,"迟到3次");
        DevelopDept worker3 = new DevDept2("G",'男',12345.6,3000,"迟到2次");
        DevelopDept worker4 = new DevDept2("H",'男',12245.6,3000,"迟到5次");
        DevelopDept worker5 = new DevDept2("I",'男',12145.6,2000,"迟到7次");
        List<DevelopDept> list1 = new ArrayList<>();
        List<DevelopDept> list2 = new ArrayList<>();
        List<TopPerformer> list3 = new ArrayList<>();
        Collections.addAll(list1,emp1,emp2,emp3,emp4);
        Collections.addAll(list2,worker1,worker2,worker3,worker4,worker5);
        System.out.println(list1);
        System.out.println(list2);
        //1. 筛选出2个部门最高工资员工  Max方法
        list1.stream().max(new Comparator<DevelopDept>() {
            @Override
            public int compare(DevelopDept o1, DevelopDept o2) {
                if ((o1.getSalary() + o1.getBonus()) > (o2.getSalary() + o2.getBonus())) {
                    return 1;
                } else if ((o1.getSalary() + o1.getBonus()) < (o2.getSalary() + o2.getBonus())) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }).map(new Function<DevelopDept, TopPerformer>() {
            @Override
            public TopPerformer apply(DevelopDept developDept) {
                TopPerformer topPerformer1 = new TopPerformer();
                topPerformer1.setName(developDept.getName());
                topPerformer1.setMoney(developDept.getSalary() + developDept.getBonus());
                list3.add(topPerformer1);
                return topPerformer1;
            }
        });
        //补充一下  map加工完后， map.get() 可以得到这个   max.get()也同理
        list2.stream().max(new Comparator<DevelopDept>() {
            @Override
            public int compare(DevelopDept o1, DevelopDept o2) {
                if ((o1.getSalary() + o1.getBonus()) > (o2.getSalary() + o2.getBonus())) {
                    return 1;
                } else if ((o1.getSalary() + o1.getBonus()) < (o2.getSalary() + o2.getBonus())) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }).map(new Function<DevelopDept, TopPerformer>() {

            @Override
            public TopPerformer apply(DevelopDept developDept) {
                TopPerformer topPerformer2 = new TopPerformer();
                topPerformer2.setName(developDept.getName());
                topPerformer2.setMoney(developDept.getSalary()+developDept.getBonus());
                list3.add(topPerformer2);
                return topPerformer2;
            }
        });
        System.out.println(list3);
        // 求平均工资，
        // 去掉最高和最低 思路： 先排序，skip（1）， limit（size-2） foreach +sum
        list1.stream().sorted((o1,o2) -> {
                return Double.compare(
                        (o1.getSalary()+o1.getBonus()),
                        (o2.getSalary()+o2.getBonus()));
        }).skip(1).limit(list1.size()-2).forEach(new Consumer<DevelopDept>() {
            @Override
            public void accept(DevelopDept developDept) {
                sum+= (developDept.getBonus()+developDept.getBonus());
            }
        });
        System.out.println("平均工资："+ (sum/list1.size()-2));
    }
}


